
(ns ca.uoit.molly.search-api
  (:require [ca.uoit.molly.lucene-molly :as lucene-molly]))

(defn search-values
  "Returns a list of value maps that match the query string.  This string is
  analyzed using an n-gram analyzer to allow for approximate matching.

    idx - Index to search
    topk - Maximum number of results to return
    q-str - Query string to search for"
  [idx topk q-str]
  (lucene-molly/search-values idx q-str topk))

(defn search-entities
  "Returns a list of entity maps that match either the query string or a
  set of constraints, depending on the arguments specified.

    idx - Index to search
    topk - Maximum number of results to return

   AND

    q - Query string OR a list of constraints
    
    Constraints consist of:
      - Entity (type, string)
      - Attribute (attrib, string)
      - Value (string)
      - Operator (AND/OR/NOT)"
  [idx topk q]
    (if (string? q)
      (lucene-molly/search-entities idx q topk)
      (lucene-molly/search-entities-by-constraints idx topk q)))

